package com.example.tourism.mapper;


import com.example.tourism.pojo.po.*;
import com.example.tourism.pojo.vo.res.HotelResVo;
import com.example.tourism.pojo.vo.res.ImgResVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HotelMapper {
    @Insert("INSERT INTO hotel(user_id,hotel_name,contact_name,contact_phone,email,hotel_address,description,state) VALUES(#{userId},#{hotelName},#{contactName},#{contactPhone},#{email},#{hotelAddress},#{description},#{state})")
    int insertHotel(HotelInfo hotelInfo);

    @Select("SELECT * FROM hotel WHERE user_id=#{userId}")
    HotelInfo selectHotelByUserId(String userId);

    @Select("SELECT * FROM hotel order By time desc")
    List<HotelInfo> selectAllHotel();

    @Update("UPDATE hotel SET state=1 WHERE id=#{id}")
    int approveApplication(String id);

    @Update("UPDATE hotel SET state=2 WHERE id=#{id}")
    int rejectApplication(String id);

    @Update("UPDATE hotel SET state=0 WHERE id=#{id}")
    int withdrawApplication(String id);


    // 得到插入数据的id
    @Insert("INSERT INTO room(id,user_id,name,type,price,room_num,status) VALUES(NULL,#{uid},#{room.name},#{room.type},#{room.price},#{room.roomNum},#{room.status})")
    @Options(useGeneratedKeys = true, keyProperty = "room.id")
    int insertRoom(Room room,@Param("uid") String uid);

    @Select("SELECT * FROM room WHERE user_id=#{id}")
    List<Room> getHotelRoomList(String id);

    @Select("SELECT url, name FROM img WHERE to_id=#{hotelId} AND type=0")
    List<ImgResVo> getRoomPhotos(String hotelId);

    @Insert("INSERT INTO img(id,type,url,to_id,name) VALUES(null,#{type},#{url},#{toId},#{name})")
    int  InsertRoomPhoto(Img  img);

    @Delete("DELETE FROM img WHERE to_id=#{id} AND type=0")
    int  deleteRoomPhoto(Integer id);

    @Update("UPDATE room SET name=#{name},type=#{type},price=#{price},room_num=#{roomNum},status=#{status} WHERE id=#{id}")
    int updateRoomInfo(Room room);

    @Select("SELECT * FROM hotel WHERE user_id=#{id}")
    HotelInfo getHotelInfo(String id);

    @Select("SELECT url, name FROM img WHERE to_id=#{id} AND type=1")
    List<ImgResVo> getHotelPhotos(String id);

    @Update("UPDATE hotel SET hotel_name=#{name},contact_name=#{contactPerson},contact_phone=#{phone},email=#{email},hotel_address=#{address} WHERE id=#{id}")
    void updateHotelInfo(HotelResVo hotelResVo);

    @Insert("INSERT INTO img(id,type,url,to_id,name) VALUES(null,#{type},#{url},#{toId},#{name})")
    void insertHotelImg(Img img);

    @Delete("DELETE FROM img WHERE to_id=#{id} AND type=1")
    void deleteHotelPhoto(Integer id);

    @Select("SELECT * FROM comment WHERE hotel_id=#{hotelId}")
    List<Comment> getHotelReviews(String hotelId);

    @Select("SELECT * FROM orders WHERE order_uid=#{orderUid}")
    Orders getOrderByOrderUid(String orderUid);

    @Select("SELECT type FROM room WHERE id=#{roomId}")
    String getRoomTypeByRoomId(String roomId);

    @Select("SELECT * FROM comment WHERE order_uid=#{orderUid}")
    Comment getCommentByOrderUid(String orderUid);

    @Update("UPDATE comment SET reply=#{reply} WHERE order_Uid=#{orderUid}")
    int submitCommentReply(@Param("orderUid") String orderUid,@Param("reply") String reply);
}
